PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Run

The Run command can function as an AppleScript command or an application command.

The application Run command launches an application if it is not already running. The application must be on a local or mounted volume. If the application is already running, then the effect of the Run command depends on the application. Some applications are not affected; others, such as SimpleText, repeat their startup procedures each time they receive a Run command.

The AppleScript Run command acts on script objects. It causes statements in a script object definition, other than handler and property definitions, to be executed. You do not use the Run command to directly execute individual script statements or to execute AppleScript or scripting addition commands.

APPLESCRIPT COMMAND SYNTAX
run [ scriptObjectVariable ]
APPLICATION COMMAND SYNTAX
run [ referenceToApplication ]
PARAMETERS
scriptObjectVariable
A variable identifier whose value is a script object. This parameter is optional if the Run command is used within an appropriate Tell statement. Class: Script
referenceToApplication
A reference of the form application nameString (see "Notes"). This parameter is optional if the Run command is used within an appropriate Tell statement. Class: Reference
RESULT

The AppleScript Run command returns the result, if any, returned by the specified script object's Run handler.

The application Run command doesn't return a result.

EXAMPLES
run application "SimpleText" tell application "SimpleText"
    run
end tell

You do not use the Run command to directly execute individual script statements or to execute AppleScript or scripting addition commands:

run (save) --WRONG!
run (beep) --WRONG! (Don't try this!)

For more information, including additional examples, see the sections listed under Notes for this command.

NOTES

To specify the name ( nameString ) of an application to run, use a string of the form " Disk : Folder1 : Folder2 :...: ApplicationName " ; for details, see References to Applications. You can also specify a string with only an application name (" ApplicationName "). In this case, if the application is not already running, AppleScript attempts to find the application using the Desktop Database maintained by the Finder.

AppleScript sends an implicit Run command whenever it begins to execute a Tell statement whose target is an application that is not already open. This can cause problems with applications such as SimpleText that normally perform specific tasks on startup, such as opening a new window. To launch an application without invoking its usual startup behavior, use the Launch command, as described in Launch. For information about using the Run and Launch commands with script applications, see Calling a Script Application From a Script.

For information about Run handlers, see Run Handlers. For information about using the Run command with script objects, see Script Objects.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)